from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic

"""
Module to represent the relationship between an asset-tagging process and physical devices
"""

class asset_type(models.Model):

    name = models.CharField(max_length=32, unique=True, help_text="name for this type of asset")
    notes = models.TextField(null=True, blank=True, help_text="notes for this type of asset")

    def notes_admin(self):
        return self.notes

    notes_admin.allow_tags = True

    def __unicode__(self):
        return self.name

    def get_absolute_url(self):
        return "/asset_types/%s" % self.id

    class Meta:

        verbose_name = "Asset Type"

class asset_tag(models.Model):

#    type = models.ForeignKey(asset_type, help_text="what type of device is this?")
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey("content_type", "object_id")



    def notes_admin(self):
        return self.notes

    notes_admin.allow_tags = True

    def __unicode__(self):
        return unicode("%s" % (self.id))

    def get_absolute_url(self):
        return "/asset_tags/%s" % self.id

    class Meta:

        verbose_name = "Asset Tag" 
